//
//  Car_ContrastConsequenceCell.m
//  CarUser
//
//  Created by ayi on 2019/1/23.
//  Copyright © 2019 王森林. All rights reserved.
//

#import "Car_ContrastConsequenceCell.h"

@implementation Car_ContrastConsequenceCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


+ (Car_ContrastConsequenceCell *)initCellWithReuseIdentifier:(NSString *)reuseIdentifier andTab:(UITableView *)tab{
    Car_ContrastConsequenceCell *cell = [tab dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[Car_ContrastConsequenceCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIView *leftBgview = [[UIView alloc]init];leftBgview.backgroundColor = Common_NavigroundColor;
        UIView *midBgview = [[UIView alloc]init];midBgview.backgroundColor = UIColor.whiteColor;
        UIView *rightBgview = [[UIView alloc]init];rightBgview.backgroundColor = UIColor.whiteColor;
        _leftTitleLab = [UILabel customInitLabWithFont:13 andTextColor:UIColor.whiteColor andAlign:NSTextAlignmentCenter];
        _tipsLab1 = [UILabel customInitLabWithFont:13 andTextColor:Common_TextColor andAlign:NSTextAlignmentCenter];
        _tipsLab2 = [UILabel customInitLabWithFont:13 andTextColor:Common_TextColor andAlign:NSTextAlignmentCenter];
        
        _tipsImgv1 = [[UIImageView alloc]init];
        _tipsImgv2 = [[UIImageView alloc]init];
        
        _lineBottom = [[UIView alloc]init];_lineBottom.backgroundColor = Common_SepeColor;
        
        UIView *line = [[UIView alloc]init];line.backgroundColor = Common_SepeColor;
        
        [self.contentView addSubview:midBgview];
        [self.contentView addSubview:leftBgview];
        [self.contentView addSubview:rightBgview];
        [self.contentView addSubview:_lineBottom];
        [self.contentView addSubview:line];
        
        [leftBgview addSubview:_leftTitleLab];
        [midBgview addSubview:_tipsLab1];
        [midBgview addSubview:_tipsImgv1];
        [rightBgview addSubview:_tipsLab2];
        [rightBgview addSubview:_tipsImgv2];

        [leftBgview mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.left.and.bottom;
            make.width.mas_equalTo(BOUNDWIDTH * 1/5);
        }];
        [midBgview mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.bottom;
            make.left.equalTo(leftBgview.mas_right);
            make.width.mas_equalTo(BOUNDWIDTH * 2/5);
        }];
        [rightBgview mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.bottom;
            make.left.equalTo(midBgview.mas_right);
            (void)make.right;
        }];
        
        [_leftTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            (void)make.centerX;
        }];
        
        [_tipsLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            (void)make.centerX;
        }];
        
        [_tipsImgv1 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            (void)make.centerX;
        }];
        
        [_tipsLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            (void)make.centerX;
        }];
        
        [_tipsImgv2 mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            (void)make.centerX;
        }];
        
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.top.and.bottom;
            make.width.mas_equalTo(.5f);
            make.right.mas_equalTo(-BOUNDWIDTH * 2/5);
        }];
        
        [_lineBottom mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.right.and.bottom;
            make.height.mas_equalTo(.5f);
            make.left.mas_equalTo(BOUNDWIDTH * 1/5);
        }];
        
        _tipsLab1.hidden = YES;
        _tipsLab2.hidden = YES;
        _tipsImgv1.hidden = YES;
        _tipsImgv2.hidden = YES;
    }
    return self;
}



- (void)setModel:(CarConsequenceModel *)model{
    _model = model;
    
    _tipsLab1.hidden = NO;
    _tipsLab2.hidden = NO;
    _tipsImgv1.hidden = YES;
    _tipsImgv2.hidden = YES;
    
    CarConsequenceChildModel *childmodel = model.childModelList.firstObject;
    _leftTitleLab.text = childmodel.title;
    _tipsLab1.text = childmodel.customTitle1;
    _tipsLab2.text = childmodel.customTitle2;
}

- (void)setChildmodel:(CarConsequenceChildModel *)childmodel{
    _childmodel = childmodel;

    _tipsLab1.hidden = YES;
    _tipsLab2.hidden = YES;
    _tipsImgv1.hidden = YES;
    _tipsImgv2.hidden = YES;
    
    _leftTitleLab.hidden = NO;
    _leftTitleLab.text = childmodel.title;
    
    if (childmodel.type == Consequence_CellType_Cell_Lab) {
        
        _tipsLab1.hidden = NO;
        _tipsLab2.hidden = NO;
        
        _tipsLab1.text = childmodel.customTitle1;
        _tipsLab2.text = childmodel.customTitle2;
        
        if ([childmodel.customTitle1 isEqualToString:childmodel.customTitle2]) {
            _tipsLab1.textColor = Common_TextColor;
            _tipsLab2.textColor = Common_TextColor;
        }else{
            _tipsLab1.textColor = UIColor.redColor;
            _tipsLab2.textColor = UIColor.redColor;
        }
        
    }else{
        
        
        if (childmodel.leftModel != nil && childmodel.rightModel != nil) {
            _tipsImgv1.hidden = NO;
            _tipsImgv1.image = IMG(@"point_black");
            
            _tipsImgv2.hidden = NO;
            _tipsImgv2.image = IMG(@"point_black");
            
            _tipsLab1.textColor = Common_TextColor;
            _tipsLab2.textColor = Common_TextColor;
        }else{
            
            if (childmodel.leftModel != nil) {
                _tipsImgv1.hidden = NO;
                _tipsImgv1.image = IMG(@"point_red");
            }else{
                _tipsLab1.hidden = NO;
                _tipsLab1.text = @"-";
                _tipsLab1.textColor = UIColor.redColor;
            }
            
            if (childmodel.rightModel != nil) {
                _tipsImgv2.hidden = NO;
                _tipsImgv2.image = IMG(@"point_red");
            }else{
                _tipsLab2.hidden = NO;
                _tipsLab2.text = @"-";
                _tipsLab2.textColor = UIColor.redColor;
            }
            
        }
    }
    
    [_leftTitleLab sizeThatFits:CGSizeMake(BOUNDWIDTH * 1/5 - 16, ceilf(self.leftTitleLab.font.lineHeight))];
}

@end
